<!DOCTYPE html>
<html xmlns="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<base th:href="@{/}"/>
<title>Insert title here</title>
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/css/Managerstyle.css}"/>
<script th:src="@{/js/jquery-3.4.1.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
</head>
<body>
	<div class="contain">
		<h3>教学楼管理</h3>
		<table class="table table-hover">
			<tr>
				<td>教学楼号</td>
				<td>教学楼名称</td>
				<td>操作</td>
			</tr>
			<tr th:each="building:${buildinglist}" th:id="|tr${building.buildingId}|">
				<td th:text="${building.buildingId}"></td>
				<td th:text="${building.buildname}"></td>
				<td>
					<a th:href="|mc/to_modifyBuilding/${building.buildingId}|">修改</a>
					<a th:href="|javascript:deletebuilding(${building.buildingId});|">删除</a>
				</td>
			</tr>
		</table>
		
		<!-- Button trigger modal -->
		<button type="button" class="btn btn-success" data-toggle="modal" data-target="#addBuilding">
		  添加新教学楼
		</button>
		
		<div class="text-center">
			<nav>
				<ul class="pagination">
					<li><a th:href="@{/mc/getAllBuilding/(pageNo=1)}">首页</a></li>
					<li><a th:href="@{/mc/getAllBuilding/(pageNo=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a></li>
					<li th:each="page:${pageInfo.navigatepageNums}">
						<a th:class="${pageInfo.pageNum}==${page}?'active'"
						   th:href="@{/mc/getAllBuilding/(pageNo=${page})}">[[${page}]]</a>
					</li>
					<li><a th:href="@{/mc/getAllBuilding/(pageNo=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a></li>
					<li><a th:href="@{/mc/getAllBuilding/(pageNo=${pageInfo.pages})}">尾页</a></li>
				</ul>
			</nav>
		</div>
		
		<!-- addBuilding -->
		<div class="modal fade" id="addBuilding" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title" id="myModalLabel">添加新教学楼</h4>
		      </div>
		      <form action="mc/addBuilding" method="post">
		      <div class="modal-body">
					<dl class="dl-horizontal">
					  <dt><label for="buildname">教学楼名称：</label></dt>
					  <dd><input type="text" required="required" id="buildname" name="buildname" placeholder="在此输入教学楼名称" class="form-control"></dd>
					</dl>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		        <input type="submit" class="btn btn-primary" value="添 加">
		      </div>
		      </form>
		    </div>
		  </div>
		</div>
	</div>
	
	<script>  
            function deletebuilding(id) {
                $.ajax({
                    url: 'mc/deleteBuilding',
                    type: 'POST',
                    data: {buildingId: id}, 
                    success: function () {
                    	  $("#tr" + id).remove(); 
                    },
                    error: function (req, status, error) {
                        alert("Ajax请求失败，错误：" + error);
                    }
                });
            }
    </script>
</body>
</html>